package com.hxkcloud.patient.activitys;

import android.os.Bundle;
import android.os.Message;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hxkcloud.patient.R;
import com.hxkcloud.patient.beans.resultbeans.BaseResultBean;
import com.hxkcloud.patient.request.MessageCode;
import com.hxkcloud.patient.request.YiJiaHuNetWorkUtils;

/**
 * Created by ray_lei on 2016/7/10.
 */
public class FeedbackActivity extends BaseActivity implements View.OnClickListener {

    private LinearLayout ll_title;
    private ImageView iv_back;
    private TextView tv_title;

    private EditText et_opinion;
    private Button btn_submit;

    private BaseResultBean resultBean;

    @Override
    protected void updateByHandler(Message msg) {
        switch (msg.what) {
            case MessageCode.NETWORKCODE_SUBMITFEEDBACKINFO_SUCCESS:
                dismisssLoading();
                if (msg.obj != null) {
                    resultBean = (BaseResultBean) msg.obj;
                    toastMsg(resultBean.getMessage());
                    finish();
                } else {
                    toastMsg(R.string.datacommitsuccess);
                    finish();
                }

                break;
            case MessageCode.NETWORKCODE_SUBMITFEEDBACKINFO_FAILURE:
                dismisssLoading();
                if (msg.obj != null) {
                    toastMsg(msg.obj.toString());
                    return;
                }

                break;

        }

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_layout_feedback);
        initView();
        initData();
        initListener();
    }

    @Override
    protected void initView() {
        ll_title = (LinearLayout) findViewById(R.id.ll_title);
        iv_back = (ImageView) findViewById(R.id.iv_title_back);
        tv_title = (TextView) findViewById(R.id.tv_title_title);
        setTitlePadding(ll_title);
        iv_back.setVisibility(View.VISIBLE);
        tv_title.setText(getResources().getText(R.string.setting_text_feedback));

        et_opinion = (EditText) findViewById(R.id.et_opinion);
        btn_submit = (Button) findViewById(R.id.feedback_btn_submit);

        iv_back.setOnClickListener(this);

    }

    @Override
    protected void initListener() {
        iv_back.setOnClickListener(this);
        btn_submit.setOnClickListener(this);
    }

    @Override
    protected void initData() {

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_title_back:
                finish();
                break;
            case R.id.feedback_btn_submit:
                String content = et_opinion.getText().toString();
                if (TextUtils.isEmpty(content)) {
                    toastMsg(this.getResources().getString(R.string.pleaseinputcontent));
                    return;
                }
                loading();
                YiJiaHuNetWorkUtils.submitFeedbackInfo(content, handler);
                break;
        }
    }
}
